package com.caird.pmp.iot.handler.impl;

import com.caird.pmp.iot.entity.DeviceShadow;
import com.caird.pmp.iot.handler.HandlerBase;
import com.caird.pmp.iot.message.IMessage;
import com.caird.pmp.iot.message.impl.*;
import io.netty.channel.Channel;
import org.springframework.stereotype.Controller;

import java.util.Date;

@Controller
public class Handler0900 extends HandlerBase {

    @Override
    public boolean handle(Channel channel, IMessage message) {

        if (!isLogin(channel))
            return false;

        DeviceMessage0900 dm = (DeviceMessage0900)message;

        if (0xF0 == (dm.getType() & 0xFF)) {
            DeviceShadow shadow = getShadow(dm.getSimNo());
            shadow.setAtTime(new Date());
            shadow.setAtCount(null == shadow.getAtCount() ? 1 : shadow.getAtCount() + 1);
            shadow.setAt(dm.getData());
            setShadow(dm.getSimNo(), shadow);
        }

        return true;
    }
}
